<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="pagebar" uri="http://neusoft.edu.cn/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() 
	                   + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>高校师生在线交流</title>
	<!-- 引入css样式文件 -->
	<!-- Bootstrap Core CSS -->
	<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
	<!-- MetisMenu CSS -->
	<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
	<!-- DataTables CSS -->
	<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
	<!-- Custom CSS -->
	<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
	<!-- Custom Fonts -->
	<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper" style="height:1%">
  <!-- 导航栏部分 -->
  <nav class="navbar navbar-default navbar-static-top" role="navigation"
		 style="margin-bottom: 0">
	<div class="navbar-header">
		<a class="navbar-brand" href="<%=basePath%>good/list.action">高校师生在线交流平台</a>
	</div>
	<!-- 导航栏右侧图标部分 -->
	<ul class="nav navbar-top-links navbar-right">
	    <!-- 邮件通知 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
				<i class="fa fa-envelope fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-messages">
				<li>
				    <a href="#">
						<div>
							<strong>张经理</strong> <span class="pull-right text-muted">
								<em>昨天</em>
							</span>
						</div>
						<div>今天晚上开会，讨论一下下个月工作的事...</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a class="text-center" href="#">
				        <strong>查看全部消息</strong>
						<i class="fa fa-angle-right"></i>
				    </a>
				</li>
			</ul>
		</li>
		<!-- 邮件通知 end -->
		<!-- 任务通知 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
			    <i class="fa fa-tasks fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-tasks">
				<li>
				    <a href="#">
						<div>
							<p>
								<strong>任务 1</strong> 
								<span class="pull-right text-muted">完成40%</span>
							</p>
							<div class="progress progress-striped active">
								<div class="progress-bar progress-bar-success"
									role="progressbar" aria-valuenow="40" aria-valuemin="0"
									aria-valuemax="100" style="width: 40%">
									<span class="sr-only">完成40%</span>
								</div>
							</div>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							<p>
								<strong>任务 2</strong> 
								<span class="pull-right text-muted">完成20%</span>
							</p>
							<div class="progress progress-striped active">
								<div class="progress-bar progress-bar-info" role="progressbar"
									aria-valuenow="20" aria-valuemin="0" aria-valuemax="100"
									style="width: 20%">
									<span class="sr-only">完成20%</span>
								</div>
							</div>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a class="text-center" href="#"> 
				        <strong>查看所有任务</strong>
						<i class="fa fa-angle-right"></i>
				    </a>
				</li>
			</ul> 
		</li>
		<!-- 任务通知 end -->
		<!-- 消息通知 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
				<i class="fa fa-bell fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-alerts">
				<li>
				    <a href="#">
						<div>
							<i class="fa fa-comment fa-fw"></i> 新回复 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							<i class="fa fa-envelope fa-fw"></i> 新消息 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							<i class="fa fa-tasks fa-fw"></i> 新任务 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							<i class="fa fa-upload fa-fw"></i> 服务器重启 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a class="text-center" href="#"> 
				        <strong>查看所有提醒</strong>
						<i class="fa fa-angle-right"></i>
				    </a>
				</li>
			</ul> 
		</li>
		<!-- 消息通知 end -->
		<!-- 用户信息和系统设置 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
				<i class="fa fa-user fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-user">
				<li><a href="#"><i class="fa fa-user fa-fw"></i>
				               用户：${USER_SESSION.userName}
				    </a>
				</li>
				<li><a href="#"><i class="fa fa-gear fa-fw"></i> 系统设置</a></li>
				<li class="divider"></li>
				<li>
					<a href="${pageContext.request.contextPath }/logout.action">
					<i class="fa fa-sign-out fa-fw"></i>退出登录
					</a>
				</li>
			</ul> 
		</li>
		<!-- 用户信息和系统设置结束 -->
	</ul>
	<!-- 左侧显示列表部分 start-->
	<div class="navbar-default sidebar" role="navigation">
		<div class="sidebar-nav navbar-collapse">
			<ul class="nav" id="side-menu">
				<li class="sidebar-search">
					<div class="input-group custom-search-form">
						<input type="text" class="form-control" placeholder="查询内容...">
						<span class="input-group-btn">
							<button class="btn btn-default" type="button">
								<i class="fa fa-search" style="padding: 3px 0 3px 0;"></i>
							</button>
						</span>
					</div> 
				</li>
				<li>
				      <a href="${pageContext.request.contextPath }/question/list.action">
				        <i class="fa fa-dashboard fa-fw" ></i> 问题管理
				      </a>
				</li>				
				
				<li>
				    <a href="${pageContext.request.contextPath }/class/list.action">
				      <i class="fa fa-tasks fa-fw"></i> 班级管理
				    </a>
				</li>		
			</ul>
		</div>
	</div>
	<!-- 左侧显示列表部分 end--> 
  </nav>
</div>
<!-- 班级信息查询部分  start-->
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header" style="padding-top:10px;">班级管理</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->
		
	<table class="table table-bordered table-hover">
		<caption>班级信息列表
			<a href="#" class="btn btn-primary role="button" data-toggle="modal" data-target="#newClassDialog"">添加</a>
		</caption>
		<thead>
			<tr>
				<th>编号</th>
				<th>班级名称</th>
				<th>课程</th>
				<th>进出权限</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${page.rows}" var="c">
				<tr>
				   <td>${c.class_id}</td>
				   <td>${c.className}</td>
				   <td>${c.course}</td>
				   <td>${c.set_enter}</td>
				   <td>
				   	  <a href=" ${pageContext.request.contextPath }/student/list.action" class="btn btn-info  btn-xs">详情</a>
				      <a href="#" class="btn btn-success  btn-xs" role="button" data-toggle="modal" data-target="#classEditDialog" onclick="editClass('${c.class_id}')">修改</a>
				      <a href="#" class="btn btn-danger  btn-xs" role="button" onclick="deleteClass('${c.class_id}')">解散</a>
          			</td>
				 </tr>
			</c:forEach>
				
		</tbody>
	</table>
	<div class="col-md-12 text-right">
		<pagebar:page url="${pageContext.request.contextPath }/class/list.action" />
	</div>
</div>

<!-- 添加班级信息模态框 -->
<div class="modal fade" id="newClassDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">添加班级信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="new_class_form">
                   
					<div class="form-group">
						<label for="new_className" class="col-sm-2 control-label">班级名称</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_className" placeholder="班级名称" name="className" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_course" class="col-sm-2 control-label">课程</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_course" placeholder="课程" name="course" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_set_enter" class="col-sm-2 control-label">进出权限</label>
						<div class="col-sm-10">
							<select	class="form-control" id="new_set_enter" name="set_enter">
								    <option value="">--请选择--</option>
									<option value="开放">开放</option>
									<option value="选修可选">选修可选</option>
									<option value="重修课">重修课</option>
							</select>
						</div>
					</div>
					
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="createClass()">添加班级</button>
			</div>
		</div>
	</div>
</div>
<!-- 添加班级信息模态框end -->		

<!-- 修改班级模态框 -->
<div class="modal fade" id="classEditDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">修改班级信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="edit_class_form">
                   <input type="hidden" id="classid" name="class_id"/>
					<div class="form-group">
						<label for="edit_set_enter" class="col-sm-2 control-label">进出权限</label>
						<div class="col-sm-10">
							<select	class="form-control" id="edit_set_enter" name="set_enter">
								    <option value="">--请选择--</option>
									<option value="开放">开放</option>
									<option value="选修可选">选修可选</option>
									<option value="重修课">重修课</option>
							</select>
						</div>
					</div>
					
				</form>
			</div>
		    <div class="modal-footer">
				    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				    <button type="button" class="btn btn-primary" onclick="updateClass()">修改用户</button>
			</div>
			</div>
			
		</div>
</div>
<!-- 修改班级模态框end -->

<!-- 引入js文件 -->
<!-- jQuery -->
<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="<%=basePath%>js/metisMenu.min.js"></script>
<!-- DataTables JavaScript -->
<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="<%=basePath%>js/sb-admin-2.js"></script>
<!-- 编写js代码 -->
<script type="text/javascript">
//清空新建班级窗口中的数据
function clearClass() {
    $("#new_className").val("");
    $("#new_course").val("");
    $("#new_set_enter").val("");

}
   //添加班级信息
   function createClass() {

     $.post("${pageContext.request.contextPath}/class/createClass.action",
		
     $("#new_class_form").serialize(),function(data){
            if(data =="OK"){
               alert("班级信息添加成功！");
               window.location.reload();
            }else{
               alert("添加班级信息失败！");
               window.location.reload();
            }
        
           });

    }
// 通过id获取修改的班级信息
	function editClass(class_id) {
		alert(class_id);
		$.post("${pageContext.request.contextPath}/class/getClassById.action",{"classid":class_id},function(data){
			 $("#classid").val(data.class_id);
	         $("#set_enter").val(data.set_enter);
		});
	}
	// 执行修改班级信息操作
	function updateClass() {
  	
		$.post("${pageContext.request.contextPath}/class/updateClass.action",$("#edit_class_form").serialize(),function(data){
			if(data =="OK"){
				alert("班级信息更新成功！");
				window.location.reload();
			}else{
				alert("班级信息更新失败！");
				window.location.reload();
			}
		});
	}
//删除班级
	function deleteClass(class_id) {
    	if(confirm('确定要解散该班级吗?')) {
			$.post("${pageContext.request.contextPath}/class/deleteClass.action",{"classid":class_id},
			function(data){
		            if(data =="OK"){
		                alert("班级解散成功！");
		                window.location.reload();
		            }else{
		                alert("解散班级失败！");
		                window.location.reload();
		            }
		        });
		    }
	}
</script>
</body>
</html>